import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/home/home_controller.dart';
import 'package:flutter_changdian_football/routers/app_routes.dart';
import 'package:flutter_changdian_football/utils/pull/pull_smart_refresher.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:get/get.dart';

// 新闻
class NewWidget extends StatelessWidget {
  const NewWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return GetBuilder<HomeController>(
      builder: (homeController) {
        return RefreshWidget<HomeController>(
          child: SingleChildScrollView(
            padding: EdgeInsets.only(top: 6.w, bottom: 20.w),
            child: Container(
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.only(
                  topLeft: Radius.circular(15.r),
                  topRight: Radius.circular(15.r)
                )
              ),
              child: Column(
                children: [
                  MasonryGridView.builder(
                    gridDelegate: const SliverSimpleGridDelegateWithFixedCrossAxisCount(crossAxisCount: 1),
                    padding: EdgeInsets.symmetric(vertical: 15.w),
                    crossAxisSpacing: 9.w,
                    mainAxisSpacing: 16.w,
                    itemCount: homeController.newsModelList.length,
                    shrinkWrap: true,
                    physics: const NeverScrollableScrollPhysics(),
                    itemBuilder: (context, index) {
                      return GestureDetector(
                        behavior: HitTestBehavior.translucent,
                        onTap: () {
                          Get.toNamed(AppRoutes.newsDetail, parameters: {
                            'newsId': '${homeController.newsModelList[index].newsId ?? ''}'
                          });
                        },
                        child: Container(
                          width: double.infinity,
                          padding: EdgeInsets.symmetric(horizontal: 17.w),
                          child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            children: [
                              Expanded(
                                child: Container(
                                  height: 72.w,
                                  padding: EdgeInsets.symmetric(vertical: 4.w),
                                  child: Column(
                                    crossAxisAlignment: CrossAxisAlignment.start,
                                    children: [
                                      SizedBox(
                                        child: Text( homeController.newsModelList[index].title ?? '', style: TextStyle(fontSize: 14.sp, color: const Color(0xff222222), height: 1.5), maxLines: 2, overflow: TextOverflow.ellipsis,),
                                      ),
                                      const Spacer(),
                                      SizedBox(
                                        child: Text(homeController.newsModelList[index].publishDatetime ?? '', style: TextStyle(fontSize: 10.sp, color: const Color(0xff9E9E9E)),),
                                      )
                                    ],
                                  ),
                                ),
                              ),
                                    
                                    
                              Container(
                                margin: EdgeInsets.only(left: 15.w),
                                width: 100.w,
                                height: 72.w,
                                decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(6.r)
                                ),
                                child: ClipRRect(
                                  borderRadius: BorderRadius.circular(6.r),
                                  child: SizedBox(
                                    height: 72.w,
                                    width: 100.w,
                                    child: Image.network(homeController.newsModelList[index].thumbnailUrl ?? '', fit: BoxFit.fill, gaplessPlayback: true, excludeFromSemantics: true,),
                                  ),
                                ),
                              )
                            ],
                          ),
                        ),
                      );
                    },
                  )
                ],
              ),
            ),
          ),
        );
      }
    );
  }
}